package com.coolpad.job.device.controller;


import com.coolpad.Utils.ExtAssert;
import com.coolpad.job.device.model.RequestDTO;
import com.coolpad.job.device.model.Response;
import com.coolpad.job.device.model.ResponseDTO;
import com.coolpad.job.device.service.KafkaSendService;
import com.coolpad.job.device.service.spider.GeoSpiderService;
import com.coolpad.job.device.util.JsonUtils;
import com.coolpad.job.device.util.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 功能描述:数据收集<br/>
 *
 * @Author:shengtao_yang
 * @Date: 2020/12/16 20:18
 * @since: 1.0.0
 */
@Slf4j
@RestController
@RequestMapping("/data/collector")
public class DataCollectController {


    //@Autowired
    //private KafkaSendService kafkaSendService;

    /*@Autowired
    private GeoSpiderService geoSpiderService;
*/
    /**
     * 设备定位上传
     * @param requestDTO encryptKey为null则data不加密
     * @return
     */
    @RequestMapping(value = "/location",method = RequestMethod.POST)
    public ResponseDTO location(@RequestBody RequestDTO requestDTO) {

        log.info("[location-collect request] - body {}", JsonUtils.beanToJson(requestDTO));
        ExtAssert.hasText("illegal request param",requestDTO.getData());
        //kafkaSendService.sendDeviceLocation(SecurityUtils.decryptRequest2Json(requestDTO));
        return Response.success.build();
    }

    /**
     * 设备定位上传
     * @param requestDTO encryptKey为null则data不加密
     * @return
     */
    @RequestMapping(value = "/location/echo",method = RequestMethod.POST)
    public String locationEcho(@RequestBody RequestDTO requestDTO) {

        log.info("[location-collect-echo request] - body {}", JsonUtils.beanToJson(requestDTO));
        ExtAssert.hasText("illegal request param",requestDTO.getData());
        return SecurityUtils.decryptRequest2Json(requestDTO);
    }

    /**
     * 扫描点
     * @return
     */
   /* @RequestMapping(value = "/scanPoint/{provinceName}",method = RequestMethod.POST)
    public ResponseDTO scanPoint(@PathVariable String provinceName) {

        geoSpiderService.scanPointToHBase(provinceName);
        return Response.success.build();
    }*/
}
